<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Touch
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: install.php 2011-04-26 11:18:13 mirlan $
 * @author     Mirlan
 */

/**
 * @category   Application_Extensions
 * @package    Touch
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Touch_Installer extends Engine_Package_Installer_Module {
	public function onPreInstall() {
		parent::onPreInstall ();
		
		$db = $this->getDb ();
		$translate = Zend_Registry::get ( 'Zend_Translate' );
		
		$select = $db->select ()->from ( 'engine4_core_modules' )->where ( 'name = ?', 'hecore' )->where ( 'enabled = ?', 1 );
		
		$hecore = $db->fetchRow ( $select );
		
		$operation = $this->_databaseOperationType;
		$module_name = $this->getOperation ()->getTargetPackage ()->getName ();
		
		$select = $db->select ()->from ( 'engine4_hecore_modules' )->where ( 'name = ?', $module_name );
		
		$module = $db->fetchRow ( $select );
		
		if ($operation == 'install') {
		
		} elseif ($operation == 'upgrade') {
		
		} else { //if ($operation == 'refresh'){
		

		}
	}
	
	public function decryptByKey($sData, $sKey = 'key') {
		$sResult = '';
		$sData = $this->decodeBase64 ( $sData );
		
		for($i = 0; $i < strlen ( $sData ); $i ++) {
			$sChar = substr ( $sData, $i, 1 );
			$sKeyChar = substr ( $sKey, ($i % strlen ( $sKey )) - 1, 1 );
			$sChar = chr ( ord ( $sChar ) - ord ( $sKeyChar ) );
			$sResult .= $sChar;
		}
		
		return $sResult;
	}
	
	public function decodeBase64($sData) {
		$sBase64 = strtr ( $sData, '-_', '+/' );
		
		return base64_decode ( $sBase64 . '==' );
	}
}